# -*- coding:utf-8 -*-
# @Author    : g1879
# @date      : 2020-11-17
# @email     : g1879@qq.com
import re

from ListPage import Xpaths, Targets, ListPage, Recorder

url = ('http://search.ccgp.gov.cn/bxsearch?searchtype=1&page_index=1&bidSort=1&buyerName=&projectId=&pinMu=0'
       '&bidType=0&dbselect=bidx&kw=广西&start_time=2020%3A05%3A17&end_time=2020%3A11%3A15'
       '&timeType=5&displayZone=&zoneId=&pppStatus=0&agentName=')

xpaths = Xpaths()
xpaths.rows = '//ul[@class="vT-srch-result-list-bid"]/li'
xpaths.set_col('项目', './a')
xpaths.next_btn = '//a[text()="下一页"]'

targets = Targets(xpaths)
targets.add_target('项目', '项目')
targets.add_target('链接', '项目', 'href')

# 定义记录器
recorder = Recorder('政府采购网.csv', 200)

page = ListPage(xpaths, url, 'd')
page.num_param = 'page_index'

txt = page('Pager({').text
total = int(re.search(r'size: (\d+),', txt, re.DOTALL).group(1))
page.pages_count = total

page.get_list(targets, recorder=recorder, count=2, wait=2)
